<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8'>
    <meta content='width=device-width, initial-scale=1.0' name='viewport'>
    <meta content='' name='description'>
    <meta content='Nils Nordman' name='author'>
    <link href='/images/howl.png' rel='shortcut icon'>
    <title>Howl :: Spec - howl.util.paths</title>
    <link href="/stylesheets/bootstrap.min.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/syntax.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/howl.css" media="screen" rel="stylesheet" type="text/css" />
    <script src="https://code.jquery.com/jquery-1.12.3.min.js" type="text/javascript"></script>
    <script src="/javascripts/bootstrap.min.js" type="text/javascript"></script>
    
    <link href='//fonts.googleapis.com/css?family=Josefin+Slab' rel='stylesheet' type='text/css'>
    <link href='//fonts.googleapis.com/css?family=Open+Sans+Condensed:700' rel='stylesheet' type='text/css'>
  </head>
  <body class='doc doc_spec doc_spec_util doc_spec_util_paths_spec'>
    <div class='container'>
      <div class='masthead'>
        <ul class='nav nav-pills'>
          <li>
            <a href='/'>
              <span class='glyphicon glyphicon-home'></span>
              Home
            </a>
          </li>
          <li>
            <a href='/doc/'>
              <span class='glyphicon glyphicon-book'></span>
              Documentation
            </a>
          </li>
          <li>
            <a href='/blog/'>
              <span class='glyphicon glyphicon-bullhorn'></span>
              Blog
            </a>
          </li>
          <li>
            <a href='/contact.html'>
              <span class='glyphicon glyphicon-inbox'></span>
              Contact
            </a>
          </li>
        </ul>
      </div>
      <ol class="breadcrumb"><li><a href="/">Home</a></li><li><a href='../../'>Howl Documentation (master branch)</a></li><li>Spec</li><li>Util</li><li>Spec - howl.util.paths</li></ol>
      <div class="spec-group spec-group-1">&#x000A;&#x000A;<h1 id="howl.util.paths">howl.util.paths</h1>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="kd">local</span><span class="w"> </span><span class="n">tmpdir</span><span class="w">&#x000A;&#x000A;</span><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">tmpdir</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">File</span><span class="p">.</span><span class="n">tmpdir</span><span class="o">!</span><span class="w">&#x000A;&#x000A;</span><span class="n">after_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">tmpdir</span><span class="o">\</span><span class="n">rm_r</span><span class="o">!</span></pre>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="get_dir_and_leftover">get_dir_and_leftover</h2>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="nc">File</span><span class="p">.</span><span class="n">mkdir</span><span class="w"> </span><span class="n">tmpdir</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="s1">'subdir'</span></pre>&#x000A;&#x000A;<h4 id="returns-the-home-dir-for-empty-input">returns the home dir for empty input</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="nc">File</span><span class="p">.</span><span class="n">home_dir</span><span class="p">,</span><span class="w"> </span><span class="s1">''</span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="n">paths</span><span class="p">.</span><span class="n">get_dir_and_leftover</span><span class="w"> </span><span class="s1">''</span><span class="p">}</span></pre>&#x000A;&#x000A;<h4 id="returns-the-root-directory-for-&quot;/&quot;">returns the root directory for &quot;/&quot;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="nc">File</span><span class="p">.</span><span class="n">home_dir</span><span class="p">.</span><span class="n">root_dir</span><span class="p">,</span><span class="w"> </span><span class="s1">''</span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="n">paths</span><span class="p">.</span><span class="n">get_dir_and_leftover</span><span class="w"> </span><span class="s1">'/'</span><span class="p">}</span></pre>&#x000A;&#x000A;<h4 id="returns-the-matched-path-and-unmatched-parts-of-a-path">returns the matched path and unmatched parts of a path</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="n">tmpdir</span><span class="p">,</span><span class="w"> </span><span class="s1">'unmatched'</span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="n">paths</span><span class="p">.</span><span class="n">get_dir_and_leftover</span><span class="w"> </span><span class="nb">tostring</span><span class="p">(</span><span class="n">tmpdir</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="s1">'unmatched'</span><span class="p">)}</span></pre>&#x000A;&#x000A;<h4 id="when-given-a-directory-path-ending-in-&quot;/&quot;,-matches-the-given-directory">when given a directory path ending in &quot;/&quot;, matches the given directory</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="n">tmpdir</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="s1">'subdir'</span><span class="p">,</span><span class="w"> </span><span class="s1">''</span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="n">paths</span><span class="p">.</span><span class="n">get_dir_and_leftover</span><span class="w"> </span><span class="nb">tostring</span><span class="p">(</span><span class="n">tmpdir</span><span class="p">)</span><span class="o">..</span><span class="s1">'/subdir/'</span><span class="p">}</span></pre>&#x000A;&#x000A;<h4 id="when-given-a-directory-path-not-ending-in-&quot;/&quot;,-matches-the-parent-directory">when given a directory path not ending in &quot;/&quot;, matches the parent directory</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="n">tmpdir</span><span class="p">,</span><span class="w"> </span><span class="s1">'subdir'</span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="n">paths</span><span class="p">.</span><span class="n">get_dir_and_leftover</span><span class="w"> </span><span class="nb">tostring</span><span class="p">(</span><span class="n">tmpdir</span><span class="p">)</span><span class="o">..</span><span class="s1">'/subdir'</span><span class="p">}</span></pre>&#x000A;&#x000A;<h4 id="unmatched-part-can-contain-slashes">unmatched part can contain slashes</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="n">tmpdir</span><span class="p">,</span><span class="w"> </span><span class="s1">'unmatched/no/such/file'</span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="n">paths</span><span class="p">.</span><span class="n">get_dir_and_leftover</span><span class="w"> </span><span class="nb">tostring</span><span class="p">(</span><span class="n">tmpdir</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="s1">'unmatched/no/such/file'</span><span class="p">)}</span></pre>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(is given a non absolute path)</span></h3>&#x000A;&#x000A;<h4 id="uses-the-home-dir-as-the-base-path">uses the home dir as the base path</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="nc">File</span><span class="p">.</span><span class="n">home_dir</span><span class="p">,</span><span class="w"> </span><span class="s1">'unmatched-asdf98y23903943masgb sdf'</span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="n">paths</span><span class="p">.</span><span class="n">get_dir_and_leftover</span><span class="w"> </span><span class="s1">'unmatched-asdf98y23903943masgb sdf'</span><span class="p">}</span></pre>&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="subtree_reader">subtree_reader</h2>&#x000A;&#x000A;<h4 id="returns-all-files-and-directories-in-a-subtree">returns all files and directories in a subtree</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="k">for</span><span class="w"> </span><span class="n">dir</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="o">*</span><span class="p">{</span><span class="s1">'a'</span><span class="p">,</span><span class="w"> </span><span class="s1">'b/c'</span><span class="p">}</span><span class="w">&#x000A;  </span><span class="p">(</span><span class="n">tmpdir</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="n">dir</span><span class="p">)</span><span class="o">\</span><span class="n">mkdir_p</span><span class="o">!</span><span class="w">&#x000A;</span><span class="k">for</span><span class="w"> </span><span class="n">file</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="o">*</span><span class="p">{</span><span class="s1">'a/x'</span><span class="p">,</span><span class="w"> </span><span class="s1">'b/y'</span><span class="p">,</span><span class="w"> </span><span class="s1">'b/c/z'</span><span class="p">}</span><span class="w">&#x000A;  </span><span class="p">(</span><span class="n">tmpdir</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="n">file</span><span class="p">).</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'a'</span><span class="w">&#x000A;&#x000A;</span><span class="n">files</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">paths</span><span class="p">.</span><span class="n">subtree_reader</span><span class="w"> </span><span class="n">tmpdir</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="s1">'a'</span><span class="p">,</span><span class="w"> </span><span class="s1">'a/x'</span><span class="p">,</span><span class="w"> </span><span class="s1">'b'</span><span class="p">,</span><span class="w"> </span><span class="s1">'b/y'</span><span class="p">,</span><span class="w"> </span><span class="s1">'b/c'</span><span class="p">,</span><span class="w"> </span><span class="s1">'b/c/z'</span><span class="p">},</span><span class="w"> </span><span class="p">[</span><span class="n">file</span><span class="o">\</span><span class="n">relative_to_parent</span><span class="p">(</span><span class="n">tmpdir</span><span class="p">)</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">file</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="o">*</span><span class="n">files</span><span class="p">]</span></pre>&#x000A;</div>&#x000A;</div>
      <div class='footer text-muted'>
        <a href='/'>
          <img width="50" height="50" class="footer-logo" src="/images/howl.png" />
        </a>
        <div class='footer-follow'>
          <p>
            <a class='twitter-follow-button' data-lang='en' data-show-count='false' href='https://twitter.com/howleditor' rel='me'>
              Follow @howleditor
            </a>
          </p>
          <p>
            <a class='twitter-share-button' data-count='none' data-hashtags='howleditor' data-lang='en' data-text='The Howl Editor, a general purpose, light-weight customizable editor.' data-url='http://howl.io' href='https://twitter.com/share'>
              Tweet
            </a>
          </p>
        </div>
        <div class='footer-blurb'>
          <div>The Howl editor.</div>
          <div>
            Copyright 2012-2016
            <a class='alert-link' href='https://github.com/howl-editor/howl/contributors'>
              The Howl Developers.
            </a>
          </div>
        </div>
      </div>
    </div>
    <script>
      <!-- / GA -->
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
      ga('create', 'UA-45283282-1', 'howl.io');
      ga('send', 'pageview');
      <!-- / Twitter -->
      !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];
      if(!d.getElementById(id)){js=d.createElement(s);js.id=id;
      js.src="//platform.twitter.com/widgets.js";
      fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
    </script>
  </body>
</html>
